/*
 * hstring.h
 *
 *  Created on: Nov 27, 2011
 *      Author: benoybose
 */

#ifndef HCSTRING_H_
#define HCSTRING_H_

typedef struct _hcstring {
    char* text;
    int length;
} hcstring;

/**
 * Creates an instance of hstring from a char array.
 *
 * @param text Pointer of characters from which the hstring has to be generated
 * @return Returns generated hstring object
 */
hcstring* hcstring_create(const char* text);

/**
 * Concatenate two hstring object to create a new third one.
 *
 * @param string1 First string
 * @param string2 String to be appended
 * @return The string concatenated by both
 */
hcstring* hcstring_concat(hcstring* string1, hcstring* string2);

/**
 * Create another instance of an hstring.
 *
 * @param string The string to be duplicated
 * @return The new string, duplicated from the given
 */
hcstring* hcstring_duplicate(hcstring* string);

/**
 * Compare two instance of hstrings
 *
 * @param string1 First hstring instance
 * @param string2 Second hstring instance
 * @return Returns same as strcmp
 */
int hcstring_compare(hcstring* string1, hcstring* string2);

/**
 * Find out the fist index of a character in the string.
 *
 * @param string The string to be searched for the character
 * @param ch The character to b searched for
 * @return Zero based position of the character in the string, or -1 if not found
 */
int hcstring_index_char(hcstring* string, char ch);

/**
 * Find out the last index of a character in the string.
 *
 * @param string The string to be searched for the character
 * @param ch The character to b searched for
 *
 * @return Zero based last position of the character in the string, or -1 if not found
 */
int hcstring_last_index_char(hcstring* string, char ch);

/**
 * Extract a substring from the given string, in given position, of given length
 *
 * @param string The string from which the substring has to be extracted
 * @param start The starting position of the substring
 * @param length The required length of substring
 */
hcstring* hcstring_substr(hcstring* string, int start, int length);

/**
 * Get the length of an hstring.
 *
 * @param string The string for which the length has to be found out.
 * @return The length of given string
 */
int hcstring_len(hcstring* string);



#endif /* HCSTRING_H_ */
